package com.order.userinterfaces;

import com.order.application.dto.OrderDTO;
import com.order.application.service.OrderService;
import com.order.userinterfaces.vo.OrderVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.order.userinterfaces.converter.OrderDTOConverter.dto2OrderVO;
import static com.order.userinterfaces.converter.OrderDTOConverter.vo2OrderDTO;

/**
 * @Author 刘志伟
 * @create 2022/9/26 11:41
 */
@RestController
@RequestMapping("/api/v1/orders")
@ResponseBody
public class OrderController {

    @Resource(name = "orderService")
    private OrderService orderService;

    @PostMapping("")
    public void createOrder(@RequestBody OrderVO orderVO){

        OrderDTO orderDTO = vo2OrderDTO(orderVO);
        orderService.createOrder(orderDTO);
    }
    @GetMapping("/{id}")
    public OrderVO getOrderById(@PathVariable String id) {

        OrderDTO orderDTO = orderService.getOrderById(id);
        return dto2OrderVO(orderDTO);
    }
}
